﻿
/**
 * Data structure that represents an action
 */
public class Edge
{
    /**
     * Costs to take this edge(action)
     */
    private float mStepCosts;

    /*
     * Connected node(state) on the "left"
     */
    private Node mLeftNode;

    /**
     * Connected node(state) on the "right"
     */
    private Node mRightNode;

    /*
     * Hide default constructor
     */
    private Edge() { }

    /*
     * Constructor
     */
    public Edge(float costs, Node left, Node right)
    {
        /** check left and right node */
        if (left == null || right == null) { throw new System.Exception("Try to create edge with empty ends"); }

        /** assign costs */
        mStepCosts = costs;

        /** consistency check */
        if (left.getState().CompareTo(right.getState()) < 0) {
            mLeftNode = left;
            mRightNode = right;
        } else if (left.getState().CompareTo(right.getState()) > 0) {
            mLeftNode = right;
            mRightNode = left;
        } else throw new System.Exception("Try to create an edge with two identicial ends");
    }

    /*
     * Override toString
     */
    public override string ToString()
    {
        return "<" + mLeftNode.ToString() + " <-> " + mRightNode.ToString() +  ", costs = " + mStepCosts + ">";
    }

    /**
     * Getter
     */
    public float getStepCost() { return mStepCosts; }

    /**
     * Get possible adjacent neighbor
     */
    public Node getAdjacentNode(Node node)
    {
        if (mLeftNode == node) { return mRightNode; }
        else if (mRightNode == node) { return mLeftNode; }
        else { return null; }
    }

} // class Edge
